package com.blast.manager.pop

import android.content.Context
import android.text.TextUtils
import android.view.KeyEvent
import com.blast.manager.R
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.wxl.common.base.AbsActivity
import io.reactivex.functions.Action
import kotlinx.android.synthetic.main.pop_delete_tip.view.*

class DeleteTipPop : CenterPopupView{

    private var acion:Action?=null
    private var sub:String?=null

    constructor(context: Context) : super(context)

    override fun getImplLayoutId(): Int {
        return R.layout.pop_delete_tip
    }

    override fun onCreate() {
        super.onCreate()
        deleteDelayCancel.setOnClickListener {
            dismiss()
        }
        deleteDelaySure.setOnClickListener {
            dismiss()
            acion?.run()
        }
        if(!TextUtils.isEmpty(sub)){
            deleteDelayContent.setText(sub)
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if(keyCode == KeyEvent.KEYCODE_F1 || keyCode == KeyEvent.KEYCODE_F1){
            deleteDelayCancel.performClick()
        }
        if(keyCode == KeyEvent.KEYCODE_F4 || keyCode == KeyEvent.KEYCODE_ENTER){
            deleteDelaySure.performClick()
        }
        return true
    }



    companion object {
        fun show(context: Context,action:Action){
            val pop = DeleteTipPop(context)
            pop.acion = action
            XPopup.Builder(context)
                .asCustom(pop)
                .show()
            (context as AbsActivity).addPop(pop)
        }
        fun show(context: Context,action:Action,sub:String){
            val pop = DeleteTipPop(context)
            pop.acion = action
            pop.sub = sub
            XPopup.Builder(context)
                .asCustom(pop)
                .show()
            (context as AbsActivity).addPop(pop)
        }
    }
}